package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Video;
import cn.wolfcode.trip.base.query.VideoQueryObject;
import cn.wolfcode.trip.base.service.IVideoService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/video")
public class VideoController {
    @Autowired
    private IVideoService videoService;
    @RequestMapping("/list")
    public String selectWrite(@ModelAttribute("qo") VideoQueryObject qo, Model model){
        qo.setOrderBy("v.id");
        qo.setState(0);
        PageInfo info = videoService.query(qo);
        model.addAttribute("pageInfo",info);
        return "video/list";
    }
    @RequestMapping("/listRelease")
    public String selectRelease(@ModelAttribute("qo") VideoQueryObject qo, Model model){
        qo.setOrderBy("v.id desc");
        qo.setState(1);
        PageInfo info = videoService.query(qo);
        model.addAttribute("pageInfo",info);
        return "videoRelease/list";
    }
    @RequestMapping("/listNg")
    public String selectNg(@ModelAttribute("qo") VideoQueryObject qo, Model model){
        qo.setOrderBy("v.id desc");
        qo.setState(-1);
        PageInfo info = videoService.query(qo);
        model.addAttribute("pageInfo",info);
        return "videoNg/list";
    }
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Video video){
        videoService.changeState(video);
        return new JSONResult();
    }
}
